package edu.nf.relaxenjoy.web.controller.app;

import edu.nf.relaxenjoy.common.result.ResultVO;
import edu.nf.relaxenjoy.common.validator.ValidatorUtils;
import edu.nf.relaxenjoy.common.validator.group.DefaultGroup;
import edu.nf.relaxenjoy.domain.dto.SearchRecordDTO;
import edu.nf.relaxenjoy.service.UserService;
import edu.nf.relaxenjoy.web.controller.BaseController;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author zhu
 * @date 2024-12-20
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/searchRecord")
public class SearchRecordController extends BaseController {

    private final UserService userService;

    /**
     * 得到当前用户所有的搜索记录
     */
    @RequestMapping("getAllSearchRecord")
    public ResultVO getAllSearchRecord(String uid) {
        List<String> result = userService.getAllSearchRecord(uid);
        return success(result);
    }


    @RequestMapping("addSearchRecord")
    public ResultVO addSearchRecord(@RequestBody SearchRecordDTO searchRecordDTO) {
        ValidatorUtils.validateEntity(searchRecordDTO,DefaultGroup.class);
        userService.addSearchRecord(searchRecordDTO);
        return success();
    }

    @RequestMapping("deleteSearchRecord")
    public ResultVO deleteSearchRecord(@RequestBody List<String> words, String uid) {
        userService.deleteSearchRecord(words, uid);
        return success();
    }

}
